#pragma once
#include "stdafx.h"
#include "DeviceManager.h"

CDeviceManager *CDeviceManager::m_pInstance = NULL;
CDeviceManager::CDeviceManager()
{

}
CDeviceManager::~CDeviceManager()
{
}

CDeviceManager::CInputManager::CInputManager()
{
	m_nInputs = 0;
	m_ppInputs.clear();
}
CDeviceManager::CInputManager::~CInputManager()
{
	m_nInputs = 0;
	m_ppInputs.clear();
}
CDeviceManager::COutputManager::COutputManager()
{
	m_nOutputs = 0;
	m_ppOutputs.clear();
}
CDeviceManager::COutputManager::~COutputManager()
{
	m_nOutputs = 0;
	m_ppOutputs.clear();
}
CDeviceManager::CMotorManager::CMotorManager()
{
	m_nMotors = 0;
	m_ppMotors.clear();
}
CDeviceManager::CMotorManager::~CMotorManager()
{
	m_nMotors = 0;
	m_ppMotors.clear();
}
void CDeviceManager::Destroy()
{
	if (m_pInstance)
	{
		delete m_pInstance;
		m_pInstance = NULL;
	}
}

BOOL CDeviceManager::Initialize(int nInputs, int nOutputs, int nMotors)
{
	m_Output.m_nOutputs = nOutputs;
	for (int i = 0; i < nOutputs; i++)
	{
		COutput * _Output = new COutput();
		_Output->ReadConfig(i);
		m_Output.m_ppOutputs.push_back(_Output);
	}
	m_Input.m_nInputs = nInputs;
	for (int i = 0; i < nInputs; i++)
	{
		CInput* _Input = new CInput();
		_Input->ReadConfig(i);
		m_Input.m_ppInputs.push_back(_Input);
	}
	m_Motor.m_nMotors = nMotors;
	for (int i = 0; i < nMotors; i++)
	{
		CMotor* _Motor = new CMotor();
		_Motor->ReadConfig(i);
		m_Motor.m_ppMotors.push_back(_Motor);
	}
	return TRUE;
}
CDeviceManager * CDeviceManager::GetInstance()
{
	if (!m_pInstance)
		m_pInstance = new CDeviceManager();
	return m_pInstance;
}

CInput * CDeviceManager::CInputManager::operator[](int nID)
{
	return m_ppInputs[nID];
}

COutput * CDeviceManager::COutputManager::operator[](int nID)
{
	return m_ppOutputs[nID];
}

CMotor * CDeviceManager::CMotorManager::operator[](int nID)
{
	return m_ppMotors[nID];
}

